package org.openfans.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Description：标签<br>
 * Date：2006-5-29<br>
 * 
 * @author pesome<br>
 * @email:pesome@gmail.com<br>
 */
public class Tag extends PersistentObject {
	public static final int ORDER_BY_SUBMIT_DATE_DESC = 0;

	public static final int ORDER_BY_HOT_DESC = 1;

	public static final int ORDER_BY_ARTICLE_COUNT_DESC = 2;

	public static final int ORDER_BY_TITLE_ASC = 3;
	
	public static final int ORDER_BY_DIGG_DESC = 4;

	private int hot;

	private int articleCount;

	/**
	 * @uml.property name="tagId"
	 */
	private int tagId;

	/**
	 * @uml.property name="title"
	 */
	private String title;

	private Set<Article> articles;

	private Fans fans;// 创建此tag的fans

	private Date submitDate;

	private Set<TagRelation> tagRelations;

	private Set<TagFeed> feeds;

	public Set<TagFeed> getFeeds() {
		return feeds;
	}

	public void setFeeds(Set<TagFeed> feeds) {
		this.feeds = feeds;
	}
	
	public void addFeed(TagFeed feed) {
		if(feeds==null){
			feeds=new HashSet<TagFeed>();
		}
		feeds.add(feed);
	}

	public void removeFeed(TagFeed feed) {
		feeds.remove(feed);
	}

	public Date getSubmitDate() {
		return submitDate;
	}

	public void setSubmitDate(Date submitDate) {
		this.submitDate = submitDate;
	}

	/**
	 * @return Returns the tagId.
	 * @uml.property name="tagId"
	 */
	public int getTagId() {
		return tagId;
	}

	/**
	 * @param tagId
	 *            The tagId to set.
	 * @uml.property name="tagId"
	 */
	public void setTagId(int tagId) {
		this.tagId = tagId;
	}

	public Set getArticles() {
		return articles;
	}

	public void setArticles(Set<Article> articles) {
		this.articles = articles;
	}

	public void addArticle(Article article) {
		if (articles == null) {
			articles = new HashSet<Article>();
		}
		articles.add(article);
		this.articleCount++;
	}

	public void removeArticle(Article article) {
		articles.remove(article);
		this.articleCount--;
	}

	/**
	 * @return Returns the title.
	 * @uml.property name="title"
	 */
	public String getTitle() {
		return title;
	}

	public Fans getFans() {
		return fans;
	}

	public void setFans(Fans fans) {
		this.fans = fans;
	}

	/**
	 * @param title
	 *            The title to set.
	 * @uml.property name="title"
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * ����˵��ȡ�����jtags�б�<br>
	 * �����ߣ��ſ�<br>
	 * ����ʱ�䣺2006-2-18<br>
	 * 
	 * @return
	 */
	public List getRelTags() {
		return null;
	}

	public int getHot() {
		return hot;
	}

	public void setHot(int hot) {
		this.hot = hot;
	}

	public void addHot(int i) {
		hot += i;
	}

	public Set<TagRelation> getTagRelations() {
		return tagRelations;
	}

	public void setTagRelations(Set<TagRelation> tagRelations) {
		this.tagRelations = tagRelations;
	}

	public void addTagRelation(TagRelation tr) {
		if (null == tagRelations) {
			tagRelations = new HashSet<TagRelation>();
		}
		tagRelations.add(tr);
	}

	public static String getOrder(int type) {
		switch (type) {
		case ORDER_BY_TITLE_ASC:
			return "title asc";
		case ORDER_BY_HOT_DESC:
			return "hot desc";
		case ORDER_BY_ARTICLE_COUNT_DESC:
			return "articleCount desc";
		case ORDER_BY_SUBMIT_DATE_DESC:
			return "tagId desc";
		case ORDER_BY_DIGG_DESC:
			return "diggCount desc";

		default:
			return "tagId desc";
		}
	}

	public int getArticleCount() {
		return articleCount;
	}

	public void setArticleCount(int articleCount) {
		this.articleCount = articleCount;
	}
}
